package mymac.com.test_3_1;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import org.json.JSONObject;

/**
 * Created by mymac on 2017/2/28.
 */

public class AddDepsActivity extends Activity {
    private EditText et_deps;
    private Button btn_adddeps;
    SharedPreferences preferences;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_adddeps);
        et_deps = (EditText) findViewById(R.id.et_deps);
        btn_adddeps = (Button) findViewById(R.id.btn_adddeps);
        preferences = getSharedPreferences("token", Activity.MODE_PRIVATE);

        btn_adddeps.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String token = preferences.getString("token", "");
                String name = et_deps.getText().toString().trim();
                String address = "http://a.xl18z.cn/api/department/insert?token=" + token + "&name=" + name;
                HttpActivity.getInstance().getErrMsg(address, new DataCallBack() {
                    @Override
                    public void onErr(Object object) {
                        String errmsg = (String) object;
                        if ("ok!".equals(errmsg)) {
                            finish();
                        }
                    }
                });
            }
        });


    }
}
